package cn.itcast.order.web;

import cn.itcast.order.config.UserConfiguartionProperties;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
@RequestMapping("/order")
//@RefreshScope
public class OrderController {

   @Autowired
   private OrderService orderService;

   @Autowired
   private UserConfiguartionProperties userConfiguartionProperties;

   @Value("${user.name}")
   private String username;


    @GetMapping("/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) {
        // 根据id查询订单并返回
        log.info("----------------------{}------------------",username);
        return orderService.queryOrderById(orderId);
    }

    @GetMapping("/getUsername")
    public String getUsername(){
        return username + "或" + userConfiguartionProperties.getName();
    }
}
